package com.wulian.common.util;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 *@Description:()
 * @author  caifulin
 * @date  2020/6/2 18:10
 * @version 1.0
 */
public class CalculationAgeUtil {
    /**
     * 功能描述: <br>
     * 〈根据身份证号输出年龄〉
     * @Param:
     * @Return:
     * @Author: caifulin
     * @Date: 2020/6/2
     */
    public static int idCardToAge(String IdNO){
        int leh = IdNO.length();
        String dates="";
        if (leh == 18) {
            //int se = Integer.valueOf(IdNO.substring(leh - 1)) % 2;
            dates = IdNO.substring(6, 10);
            SimpleDateFormat df = new SimpleDateFormat("yyyy");
            String year=df.format(new Date());
            int age = Integer.parseInt(year)-Integer.parseInt(dates);

            return age;
        }else{
            dates = IdNO.substring(6, 8);
            return Integer.parseInt(dates);
        }

    }
}